package com.example.Housekeeping.controller;

import com.example.JavaDemo.domain.Community;
import com.example.comon.domain.LoginUser;
import com.example.comon.domain.R;
import com.example.comon.utils.UserUtil;
import com.example.Housekeeping.domain.Bo.HouseOrderBo;
import com.example.Housekeeping.domain.HouseOrder;
import com.example.Housekeeping.domain.Vo.HouseOrderVo;
import com.example.Housekeeping.service.IHouseOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/HouseOrder")
@Api(value = "houseOrder",tags = "家政订单控制器")
public class HouseOrderController {
    @Autowired
    private IHouseOrderService houseOrderService;


    @GetMapping("/getHouseOrderList")
    @ApiOperation("获取家政订单列表")
    public R<List<HouseOrderVo>> getOrderList(HouseOrderBo bo){
        HouseOrder houseOrder = new HouseOrder();
        houseOrder.setOrderId(bo.getOrderId());

        List<HouseOrderVo> list =  houseOrderService.selectHouseOrder(houseOrder);
        return R.success(list);
    }
    @GetMapping("/getHouseOrderByAccount")
    @ApiOperation("根据账号获取家政订单")
    public R<List<HouseOrderVo>> getHouseOrderByAccount(HouseOrderBo bo){
        HouseOrder houseOrder = new HouseOrder();
        houseOrder.setUserAccont(bo.getUserAccont());

        List<HouseOrderVo> list =  houseOrderService.selectHouseOrder(houseOrder);
        return R.success(list);
    }

    @PostMapping("/addHouseOrder")
    @ApiOperation("增加订单")
    public R<List<Community>> addHouseOrder(@RequestBody HouseOrderBo bo){
        HouseOrder houseOrder = new HouseOrder();
        houseOrder.setServiceType(bo.getServiceType());
        houseOrder.setUserNumber(bo.getUserNumber());
        houseOrder.setNotes(bo.getNotes());
        houseOrder.setAddress(bo.getAddress());
        houseOrder.setUpTime(bo.getUpTime());
        houseOrder.setAddress(bo.getAddress());
        houseOrder.setState(bo.getState());
        houseOrder.setUserAccont(bo.getUserAccont());
        houseOrder.setPayType(bo.getPayType());
        houseOrder.setMoney(bo.getMoney());
          LoginUser loginUser = UserUtil.getLoginUser();//获取当前登录账号
        houseOrder.setCreateBy(Integer.valueOf(loginUser.getUserId()));
        houseOrderService.addHouseOrder(houseOrder);
        return R.success();
    }

    @PostMapping("/updateHouseOrderById")
    @ApiOperation("修改订单")
    public R updateHouseOrderById(@RequestBody HouseOrder houseOrder){
        houseOrderService.updateHouseOrderById(houseOrder);
        return R.success();
    }

    @DeleteMapping("/delHouseOrderById")
    @ApiOperation("删除订单")
    public R delHouseOrderById(String id){
        houseOrderService.delHouseOrderById(id);
        return R.success();
    }
}
